@echo off
chcp 936 >nul
echo Starting compilation process...
echo.

:: Compile common module
echo Compiling common-module...
cd /d F:\shopping\common-module
call mvn clean install -DskipTests
if errorlevel 1 (
    echo Compilation failed for common-module
    pause
    exit /b 1
)

echo Compiling auth-service...
cd /d F:\shopping\auth-service
call mvn clean package -DskipTests
if errorlevel 1 (
    echo Compilation failed for auth-service
    pause
    exit /b 1
)

echo Compiling user-service...
cd /d F:\shopping\user-service
call mvn clean package -DskipTests
if errorlevel 1 (
    echo Compilation failed for user-service
    pause
    exit /b 1
)

echo Compiling product-service...
cd /d F:\shopping\product-service
call mvn clean package -DskipTests
if errorlevel 1 (
    echo Compilation failed for product-service
    pause
    exit /b 1
)

echo Compiling order-service...
cd /d F:\shopping\order-service
call mvn clean package -DskipTests
if errorlevel 1 (
    echo Compilation failed for order-service
    pause
    exit /b 1
)

echo Compiling gateway-service...
cd /d F:\shopping\gateway-service
call mvn clean package -DskipTests
if errorlevel 1 (
    echo Compilation failed for gateway-service
    pause
    exit /b 1
)

echo.
echo All services compiled successfully!
echo.
echo Starting services...
echo.

echo Starting auth-service on port 8084...
start "auth-service" cmd /k "cd /d F:\shopping\auth-service && java -jar target\auth-service-1.0.0.jar"
timeout /t 3 >nul

echo Starting user-service on port 8081...
start "user-service" cmd /k "cd /d F:\shopping\user-service && java -jar target\user-service-1.0.0.jar"
timeout /t 3 >nul

echo Starting product-service on port 8082...
start "product-service" cmd /k "cd /d F:\shopping\product-service && java -jar target\product-service-1.0.0.jar"
timeout /t 3 >nul

echo Starting order-service on port 8083...
start "order-service" cmd /k "cd /d F:\shopping\order-service && java -jar target\order-service-1.0.0.jar"
timeout /t 3 >nul

echo Starting gateway-service on port 8080...
start "gateway-service" cmd /k "cd /d F:\shopping\gateway-service && java -jar target\gateway-service-1.0.0.jar"

echo.
echo All services started!
echo.
echo Service ports:
echo - Gateway: 8080
echo - Auth: 8084
echo - User: 8081
echo - Product: 8082
echo - Order: 8083
echo.
echo Nacos Console: http://192.168.152.48:8848/nacos
echo.
echo Press any key to exit...
pause